package com.huangd.platform.config;


import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.builders.ResponseMessageBuilder;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.ResponseMessage;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@Configuration
@EnableSwagger2WebMvc
@EnableKnife4j
public class SwaggerConfig implements WebMvcConfigurer {



    @Bean
    public Docket createRestApi() {
        return  new Docket(DocumentationType.SWAGGER_2)
                .useDefaultResponseMessages(false)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.huangd.platform.modules.sys"))
                .paths(PathSelectors.any())
                .build()
                .groupName("sys接口")
                .pathMapping("/");
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("RESTful APIs")
                .description("后台管理系统接口文档")
                .termsOfServiceUrl("http://localhost:80/")
                .contact("huangd")
                .version("1.0")
                .build();
    }

    @Bean
    public Docket createRestApiJob() {
        return  new Docket(DocumentationType.SWAGGER_2)
                .useDefaultResponseMessages(false)
                .apiInfo(apiInfoJob())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.huangd.platform.modules.job"))
                .paths(PathSelectors.any())
                .build()
                .groupName("定时器接口")
                .pathMapping("/");

    }

    public ApiInfo apiInfoJob() {
        return  new ApiInfoBuilder()
                .title("定时器 API")
                .description("后台管理系统接口文档")
                .termsOfServiceUrl("http://localhost:80/")
                .contact("huangd")
                .version("1.0")
                .build();
    }

    @Bean
    public Docket createRestApiData() {
        return  new Docket(DocumentationType.SWAGGER_2)
                .useDefaultResponseMessages(false)
                .apiInfo(apiInfoData())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.huangd.platform.modules.game"))
                .paths(PathSelectors.any())
                .build()
                .groupName("游戏数据接口")
                .pathMapping("/");

    }

    public ApiInfo apiInfoData() {
        return  new ApiInfoBuilder()
                .title("游戏数据API")
                .description("后台管理系统接口文档")
                .termsOfServiceUrl("http://localhost:80/")
                .contact("huangd")
                .version("1.0")
                .build();
    }

}